﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace TKT.Lifter.CIM.Lifter.TibcoMsg.Mes
{
    public class TraceListRequest : MessageBody
    {
        public string MachineName { get; set; }
        public string UnitName { get; set; }
        public string TRID { get; set; }
        public string DSPER { get; set; }
        public string TOTSMP { get; set; }
        public string REPGSZ { get; set; }
        public List<string> SVIDList { get; set; }

        public TraceListRequest()
            : base("TraceListRequest")
        { }

        public override System.Xml.Linq.XElement ToXElement()
        {
            XElement body = new XElement("Body");
            body.Add(new XElement("MACHINENAME", this.MachineName));
            body.Add(new XElement("UNITNAME", this.UnitName));
            body.Add(new XElement("TRID", this.TRID));
            body.Add(new XElement("DSPER", this.DSPER));
            body.Add(new XElement("TOTSMP", this.TOTSMP));
            body.Add(new XElement("REPGSZ", this.REPGSZ));

            XElement svList = new XElement("SVIDLIST");
            if (this.SVIDList != null)
            {
                foreach (var strSVID in this.SVIDList)
                {
                    svList.Add(new XElement("SVID", strSVID));
                }
            }

            return body;
        }

        public override void Parse(System.Xml.Linq.XElement body)
        {
            this.MachineName = body.Element("MACHINENAME").Value;
            this.UnitName = body.Element("UNITNAME").Value;
            this.TRID = body.Element("TRID").Value;
            this.DSPER = body.Element("DSPER").Value;
            this.TOTSMP = body.Element("TOTSMP").Value;
            this.REPGSZ = body.Element("REPGSZ").Value;

            this.SVIDList = new List<string>();
            List<XElement> svList = body.Element("SVIDLIST").Elements("SVID").ToList();
            foreach (var xelementSVID in svList)
            {
                this.SVIDList.Add(xelementSVID.Value);
            }
        }
    }
}
